package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.utils.RangeInt;

public class S_HPUpdate extends ServerBasePacket {
  private byte[] _byte;
  
  private static final RangeInt _hpRange = new RangeInt(1, 32767);
  
  public S_HPUpdate(int currentHp, int maxHp) {
    this._byte = null;
    buildPacket(currentHp, maxHp);
  }
  
  public S_HPUpdate(L1PcInstance pc) {
    this._byte = null;
    buildPacket(pc.getCurrentHp(), pc.getMaxHp());
  }
  
  public void buildPacket(int currentHp, int maxHp) {
    writeC(225);
    writeH(_hpRange.ensure(currentHp));
    writeH(_hpRange.ensure(maxHp));
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
